@model dynamic

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>登录</title>
</head>
<body>
<div>
    <script src="/js/axios.js" ></script>
    <script src="/js/form-serialize.js" ></script>
    <form id="loginForm">
        用户名:<input type="text" name="userName" /><br/>
        密码:<input type="password" name="password" /> <br/>
        30天免登录:<input type="checkbox" name="checkMe" value="1" /><br/>
        <input type="button" id="btnLogin" value="登录" />
    </form>
    <script>
        const btnLogin = document.querySelector("#btnLogin");
        const loginForm = document.querySelector("#loginForm");
        btnLogin.addEventListener("click",function(){
            const data =  serialize(loginForm);
            //console.log("data==",data);
            if(data===""){
                alert("用户名或密码不能为空!");
                return;
            }
            console.log("data==",data);
            axios({
                method:"post",
                url:"/login/userLogin",
                data
            }).then(function({data:res}){
                if(res.code===200){
                    if("@ViewBag.ReturnUrl"){
                        window.location.href = "@ViewBag.ReturnUrl";
                    }else{
                        window.location.href ="/home/index";
                    }
                }else{
                    alert(res.msg);
                }
            })
        })
    </script>
</div>
</body>
</html>